/*
 * Page: 关于我们
 * Author: Truexin
 * Date: 2016/11/21
 *
 * ReviseAuthor: ''
 * ReviseDate: ''
 */

(function () {
    
    $(document).ready(()=> {
        let tab_bar = $('#tab_bar > li');
        let banner = $('.target');
        
        $('#tab_bar').find('li').eq(0).addClass('active');
        $('.banner').unslider({
            speed: 500,               //  The speed to animate each slide (in milliseconds)
            delay: 3000,              //  The delay between slide animations (in milliseconds)
            arrows: false,
            autoplay: true,
            complete: function () {
            },  //  A function that gets called after every slide animation
            keys: true,               //  Enable keyboard (left, right) arrow shortcuts
            dots: true,               //  Display dot navigation
            fluid: true              //  Support responsive design. May break non-responsive designs
        });

        $('.tab-ctr').hide().eq(0).show();

        tab_bar.click(function () {
            tab_bar.removeClass('active')
            $(this).addClass('active')
            $('.tab-ctr').hide().eq($(this).index()).show();
        })

        banner.click(function () {
            let id = $(this).find('a').attr('id').split('_')[1],
                $this = $('#' + id);
            // console.log($this.offset().top)
            // console.log(screen.availWidth)
            tab_bar.removeClass('active');
            tab_bar.eq($this.index() - 1).addClass('active');
            $('.tab-ctr').hide();
            $this.show();

            let top = $this.offset().top - tab_bar.innerHeight();
            console.log($this.offset().top)
            // $("html, body").animate({
            //     scrollTop: screen.availWidth < 450 ? 240 : 390
            // }, 1000);
            $('body').animate({scrollTop:top},600);

        })
    });

    //解决导航全部active问题

    $('#top-nav').find('a').removeClass('active'); //pc
    $('#top-nav').find('a').eq(0).addClass('active');

    $('.links').find('li').removeClass('active'); //phone
    $('.links').find('li').eq(0).addClass('active');
})();
